package com.dailyblue.java.standard.interview.offer1;

import java.math.BigDecimal;

public class CalculateMethod2 implements CalculateValue {
    @Override
    public BigDecimal calculateFruitValue(BigDecimal weight, BigDecimal price) {
        //打折后价格
        BigDecimal valueResult = null;
        //总价是否满 100 元基准
        BigDecimal priceBaseValue = new BigDecimal("100");
        //重量是否满 10 斤的基准
        BigDecimal weightBaseValue = new BigDecimal("10");
        //每满 100 减去的标准
        BigDecimal subValue = new BigDecimal("30");
        //打折前价格
        BigDecimal beforeDiscount = null;
        //折扣
        BigDecimal rate = new BigDecimal("0.8");
        // 打折前价格
        beforeDiscount = weight.multiply(price);
        System.out.println("原价是："+beforeDiscount);
        // 满百减三十的写法
        if(beforeDiscount.compareTo(priceBaseValue)>0){
            BigDecimal remainder = beforeDiscount.subtract(beforeDiscount.remainder(priceBaseValue)).divide(priceBaseValue);
            return beforeDiscount.subtract(remainder.multiply(subValue));
        }
        // 重量大于10斤的操作
        if(weight.compareTo(weightBaseValue)>0){
            return beforeDiscount.multiply(rate);
        }
        return beforeDiscount;
    }
}
